<template>
  <div class="divBox">
    <div class="root">
      <div class="top-title">
        <div class="pro-title">平台审批管理</div>
        <button class="feishu-btn" @click="jumpToFeishu">
          打开飞书文档
        </button>
      </div>
      <div class="content-area">
        <div class="info-text">
          <p>正在跳转到飞书云文档...</p>
          <p class="span-text">
            <span>飞书文档将实时同步系统中的项目数据，可查看项目进度以及对其管理跟进</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { openUrlInNewWindow } from "@/libs/OpenHelper";
import { getFeishuInformation, getFeishuFormInformation } from "@/api/feishuApi";

export default {
  name: "approve",

  data() {
    return {
      // 飞书云文档表格地址
      fileUrl: "https://zfx2bso66l.feishu.cn/sheets/shtcnbYcQtLLL3qrapu0gj1xELe",
      isLoading: false,
      // 飞书相关配置
      app_id: "cli_a205c375b139d013",
      code: "",
      openId: "",
      signature: "",
      appId: "",
      timestamp: "",
      nonceStr: "",
      url: "",
      jsApiList: ["DocsComponent"],
      lang: "",
      isShow: false,
      fileToken: "",
      positionList: [],
      position: "",
      templateNum: '',
    };
  },

  methods: {
    /**
     * 跳转到飞书云文档
     */
    jumpToFeishu() {
      this.isLoading = true;
      
      try {
        // 使用新窗口打开飞书文档
        openUrlInNewWindow(this.fileUrl);
        
        // 显示成功消息
        this.$message.success('正在打开飞书文档...');
        
        // 记录跳转日志
        console.log('跳转到飞书文档:', this.fileUrl);
        
      } catch (error) {
        console.error('跳转飞书文档失败:', error);
        this.$message.error('跳转失败，请重试');
      } finally {
        // 重置加载状态
        setTimeout(() => {
          this.isLoading = false;
        }, 1000);
      }
    },

    /**
     * 自动跳转到飞书文档（页面加载时）
     */
    autoJumpToFeishu() {
      this.$message({
        type: 'info',
        duration: 2000,
        message: '正在跳转到飞书云文档...'
      });
      
      // 延迟跳转，让用户看到提示信息
      setTimeout(() => {
        this.jumpToFeishu();
      }, 1500);
    },

    /**
     * 获取飞书信息（如果需要）
     */
    async getFeishuInfo() {
      try {
        const params = {
          code: this.code,
          app_id: this.app_id
        };
        
        const response = await getFeishuInformation(params);
        console.log('飞书信息获取成功:', response);
        
        return response;
      } catch (error) {
        console.error('获取飞书信息失败:', error);
        return null;
      }
    },

    /**
     * 获取飞书表单信息（如果需要）
     */
    async getFeishuFormInfo() {
      try {
        const params = {
          code: this.code,
          app_id: this.app_id
        };
        
        const response = await getFeishuFormInformation(params);
        console.log('飞书表单信息获取成功:', response);
        
        return response;
      } catch (error) {
        console.error('获取飞书表单信息失败:', error);
        return null;
      }
    }
  },
  
  mounted() {
    // 页面加载时自动跳转到飞书文档
    this.autoJumpToFeishu();
  },
  
  created() {
    // 组件创建时的初始化逻辑
    console.log('平台审批管理页面初始化');
  },
};
</script>
<style scoped>
.root {
  padding: 30px;
  background: #ffffff;
  box-shadow: 0 2px 8px 0 #eaf0f3;
  border-radius: 8px;
  overflow: auto;
  font-family: PingFangSC-Regular, PingFang SC;
  min-height: 400px;
}
.top-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eaf0f3;
}
.pro-title {
  font-size: 20px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #24A776;
  line-height: 20px;
}
.feishu-btn {
  background: #26B581;
  border-radius: 4px;
  padding: 12px 20px;
  color: #ffffff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
}
.feishu-btn:hover {
  background: #1e9a6b;
  transform: translateY(-1px);
}
.feishu-btn:active {
  opacity: 0.8;
  transform: translateY(0);
}
.content-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.info-text {
  text-align: center;
}

.info-text p {
  margin: 10px 0;
  font-size: 16px;
  color: #242B35;
}

.span-text {
  margin-top: 20px;
}

.span-text > span {
  font-size: 14px;
  font-weight: 400;
  color: #808EA5;
  line-height: 20px;
}

.divBox {
  margin: 20px;
  background: #f2f5f7;
  min-height: calc(100vh - 40px);
}

</style>
